package org.datacoder.geocoding.datastructures.points

import org.datacoder.geocoding.datastructures.geoshapes.*
import org.datacoder.geocoding.jurisdiction.*

class PairedRangeTrees implements PointsWithinRectangleFinder {

    RangeTree hzTree
    RangeTree vtTree

    public PairedRangeTrees(Collection<Jurisdiction> jurisdictions){
        hzTree = new RangeTree(jurisdictions, GeoShape.LON)
        vtTree = new RangeTree(jurisdictions, GeoShape.LAT)
    }

    public Set<Jurisdiction> findPointsWithinRectangle(GeoRectangle gr){
        Set<Jurisdiction> hzJurisdictions = hzTree.findPointsWithinInterval(gr.lon1, gr.lon2)
        Set<Jurisdiction> vtJurisdictions = vtTree.findPointsWithinInterval(gr.lat1, gr.lat2)
        hzJurisdictions.retainAll(vtJurisdictions)
        return hzJurisdictions
    }

}

